<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html lang="zh-CN">
<head>
<style type="text/css">
#valDiv {
	border: 1px solid gray;
	width: 800px;
	height: 300px;
	background-color: #ccc;
}
td{
	padding: 10px;
}
.jms-listen,.act-listen{
	color: white;
	background-color: green;
}
</style>
<title>脚本</title>
</head>
<body>
	<a href="script_form.htm" target="_blank">添加</a>
	<table border="1">
		<thead>
			<tr>
				<th>序</th> 
				<th>CODE</th>
				<th>状态</th>
				<th>名称</th> 
				<th>监听消息</th>
				<th>监听活动</th>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${scriptList }" var="scriptDO" varStatus="index">
				<tr script_id="${scriptDO.id }">
					<td>${index.index+1 }</td> 
					<td>${scriptDO.id }</td>
					<td class="status">${scriptDO.status }</td>
					<td>${scriptDO.name }</td> 
					<td>${scriptDO.invokeType=="jms-topic"||scriptDO.invokeType=="jms-queue"? scriptDO.invokeCode:"--" } <span class="jms-listen"></span></td>
					<td>${scriptDO.invokeType=="act-join-event"? scriptDO.invokeCode:"--" } <span class="act-listen"></span></td>
					<td><fmt:formatDate value="${scriptDO.beginTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
					<td><fmt:formatDate value="${scriptDO.endTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
					<td>
						<a href="script_execute_log.jsp?scriptId=${scriptDO.id }" target="_blank">Log</a>
						<a href="script_form.htm?id=${scriptDO.id }" target="_blank">修改</a>
						<button script_id="${scriptDO.id }" class="btnDel">删除</button>
						<button script_id="${scriptDO.id }" class="btnStartListen">开启</button>
						<button script_id="${scriptDO.id }" class="btnStopListen">停止</button></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</body>
<script src="../static/jquery-1.11.0.js"></script>
<script type="text/javascript">
	$(function() {
		$(".btnDel").click(function() {
			var p = {
				t : new Date(),
				id : $(this).attr("script_id")
			};
			$.post("script_del.htm", p, function(data) {
				alert(JSON.stringify(data));
			}, "json");
		});
		$(".btnStartListen").click(function() {
			var p = {
				t : new Date(),
				id : $(this).attr("script_id")
			};
			$.post("script_start_listen.htm", p, function(data) {
				$("button[script_id='"+data.id+"'].btnStartListen").prop("disabled",true); 
				$("button[script_id='"+data.id+"'].btnStopListen").prop("disabled",false); 
				$("tr[script_id='"+data.id+"']").find(".status").html("run"); 
			}, "json");
		});
		$(".btnStopListen").click(function() {
			var p = {
				t : new Date(),
				id : $(this).attr("script_id")
			};
			$.post("script_stop_listen.htm", p, function(data) {
				$("button[script_id='"+data.id+"'].btnStartListen").prop("disabled",false); 
				$("button[script_id='"+data.id+"'].btnStopListen").prop("disabled",true); 
				$("tr[script_id='"+data.id+"']").find(".status").html("stop"); 
			}, "json");
		});

		$("button.btnStartListen").prop("disabled",false); 
		$("button.btnStopListen").prop("disabled",true); 
		$.post("script_listen_status_list.htm",{
			t:new Date()
		},function(data){ 
			for(var i in data["jms-listen"]){
				var tr = $("tr[script_id='"+data["jms-listen"][i]+"']");
				tr.find(".jms-listen").html("listen");
				tr.find(".btnStartListen").prop("disabled",true);  
				tr.find(".btnStopListen").prop("disabled",false);  
			} 
			for(var i in data["act-listen"]){
				var tr = $("tr[script_id='"+data["act-listen"][i]+"']");
				tr.find(".act-listen").html("listen");
				tr.find(".btnStartListen").prop("disabled",true);  
				tr.find(".btnStopListen").prop("disabled",false);  
			} 
		},"json");
	});
</script>
</html>
